{% extends "admin/change_form.html" %}
{% load i18n admin_urls static admin_modify %}

{% block after_field_sets %}

{% endblock %}


{% block inline_field_sets %}
    {{ block.super }}
    <script>
        var jq;
        (function ($) {
            $(document).ready(function ($) {
                var rs = $("input[id*='is_default']");
                for (var i = 0; i < rs.length; i++) {
                    $(rs[i]).on('click', function (event) {

                        var list = $("input[id*='is_default']");
                        for (var j = 0; j < list.length; j++) {
                            if (event.currentTarget.id != $(list[j])[0].id) {
                                $(list[j]).removeAttr("checked")
                            }
                        }
                    });
                }
                jq = $;

                $('#project_form').submit(function () {
                    default_projects = $("input[id$='is_default']");
                    var flag = false;
                    for (var i = 0; i < default_projects.length; i++) {
                        if (default_projects[i].checked == true) {
                            flag = true;
                            break;
                        }
                    }
                    if (flag == false) {
                        alert('请为此业务选择一个默认部署版本');
                        return false
                    } else {
                        return true;
                    }

                })
            });
        })(django.jQuery);
    </script>
{% endblock %}